package it.ap.sa.core.dao.util;

import java.io.Serializable;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.SQLQuery;
import org.hibernate.type.Type;
/**
 * @author Alessandro Paolillo
 */
public class ExporterSqlQueryBean implements Serializable{

	private static final long serialVersionUID = -2477486028420504324L;
	/**
	 * Costruttore
	 * @param sql. Query sql (se ha parametri devono essere named)
	 * @param beanResult. Bean di output ({@link SQLQuery#setResultTransformer(org.hibernate.transform.ResultTransformer)})
	 * @param mapFieldsOutput. Mappa contenente i field di input ({@link SQLQuery#addScalar(String, org.hibernate.type.Type)})
	 * @param parameterNames. Mappa con gli eventuali parametri ({@link SQLQuery#setParameter(String, Object)})
	 */
	public ExporterSqlQueryBean(String              sql
			                   ,Class<?>            beanResult
			                   ,Map<String, Type>   mapFieldsOutput
			                   ,Map<String, Object> parameterNames
	) throws IllegalArgumentException{
		super();

		if(StringUtils.isBlank(sql))
			throw new IllegalArgumentException("sql deve essere valorizzta");
		if(beanResult == null)
			throw new IllegalArgumentException("beanResult deve essere valorizzto");
		if(mapFieldsOutput == null)
			throw new IllegalArgumentException("mapFieldsOutput deve essere valorizzto");
		
		this.sql             = sql;
        this.beanResult      = beanResult;
        this.mapFieldsOutput = mapFieldsOutput;
        this.parameterNames  = parameterNames;
	}
	/**
	 * Costruttore
	 * @param sql. Query sql (se ha parametri devono essere named)
	 * @param beanResult. Bean di output ({@link SQLQuery#setResultTransformer(org.hibernate.transform.ResultTransformer)})
	 * @param mapFieldsOutput. Mappa contenente i field di input ({@link SQLQuery#addScalar(String, org.hibernate.type.Type)})
	 */
	public ExporterSqlQueryBean(String            sql
			                   ,Class<?>          beanResult
			                   ,Map<String, Type> mapFieldsOutput
	) throws IllegalArgumentException{
		this(sql, beanResult, mapFieldsOutput, null);
	}
	/**
	 * Query sql da eseguire
	 */
	private String sql;
	/**
	 * Bean risultato
	 */
	private Class<?> beanResult;
	/**
	 * Mappa con le colonne di output
	 */
	private Map<String, Type> mapFieldsOutput;
	/**
	 * Mappa con i parametri da applicare a query
	 */
	private Map<String, Object> parameterNames;
	/**
	 * @return the sql
	 */
	public String getSql() {
		return sql;
	}
	/**
	 * @return the beanResult
	 */
	public Class<?> getBeanResult() {
		return beanResult;
	}
	/**
	 * @return the mapFieldsOutput
	 */
	public Map<String, Type> getMapFieldsOutput() {
		return mapFieldsOutput;
	}
	/**
	 * @return the parameterNames
	 */
	public Map<String, Object> getParameterNames() {
		return parameterNames;
	}
}
